home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / System7 tools / Frontier / Frontier SDK 2.1 / Toolkits / IAC Tools / iacapps.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-20  |  4.5 KB  |  219 lines  |  [TEXT/KAHL]

  1.  
  2. /*© Copyright 1988-1992 UserLand Software, Inc.  All Rights Reserved.*/
  3.  
  4. #include "iacinternal.h"
  5.  
  6.  
  7. /*
  8. 8/24/92 DW: The routines in this file are usually only needed in double-
  9. clickable applications.
  10. */
  11.  
  12.  
  13. OSErr IACdrivefilelist (tyFScallback handlespecroutine) {
  14.     
  15.     /*
  16.     the opendoc and printdoc required events take a list of filespecs as a 
  17.     parameter. we factor out the common code, and make it a little easier for an
  18.     application to handle these events.
  19.     
  20.     you supply a callback routine that handles a single filespec, you could
  21.     print it or open it, depending on which of the required events is being
  22.     invoked.
  23.     */
  24.  
  25.     AEDesc desc;
  26.     long ctfiles;
  27.     DescType actualtype;
  28.     long actualsize;
  29.     AEKeyword actualkeyword;
  30.     FSSpec fs;
  31.     long i;
  32.     OSErr ec;
  33.                         
  34.     ec = AEGetKeyDesc (IACglobals.event, keyDirectObject, typeAEList, &desc);
  35.     
  36.     IACglobals.errorcode = ec;
  37.     
  38.     if (ec != noErr) 
  39.         return (ec);
  40.         
  41.     ec = AECountItems (&desc, &ctfiles);
  42.     
  43.     IACglobals.errorcode = ec;
  44.     
  45.     if (ec != noErr) 
  46.         return (ec);
  47.                 
  48.     for (i = 1; i <= ctfiles; i ++) {
  49.     
  50.         ec = AEGetNthPtr (
  51.             &desc, i, typeFSS, &actualkeyword, &actualtype, 
  52.             
  53.             (Ptr) &fs, sizeof (fs), &actualsize);
  54.                             
  55.         IACglobals.errorcode = ec;
  56.     
  57.         if (ec != noErr) {
  58.         
  59.             AEDisposeDesc (&desc);
  60.             
  61.             return (ec);
  62.             }
  63.             
  64.         if (!(*handlespecroutine) (&fs))
  65.             return (-1);
  66.         } /*for*/
  67.         
  68.     return (noErr);
  69.     } /*IACdrivefilelist*/
  70.  
  71.  
  72. static OSType IACgetprocesscreator (void) {
  73.     
  74.     /*
  75.     get the 4-character creator identifier for the application we're running 
  76.     inside of.
  77.     */
  78.     
  79.     ProcessSerialNumber psn;
  80.     ProcessInfoRec info;
  81.     
  82.     GetCurrentProcess (&psn);
  83.     
  84.     info.processInfoLength = (long) sizeof (info);
  85.     
  86.     info.processName = nil;
  87.     
  88.     info.processAppSpec = nil;
  89.     
  90.     GetProcessInformation (&psn, &info);
  91.     
  92.     return (info.processSignature);
  93.     } /*IACgetprocesscreator*/
  94.     
  95.     
  96. static pascal OSErr CoerceTargetIDToType (DescType typecode, Ptr dataptr, Size datasize, DescType totype, long refcon, AEDesc *result) {
  97.     
  98.     TargetID target;
  99.     ProcessSerialNumber psn;
  100.     ProcessInfoRec info;
  101.     Ptr addressoftype;
  102.     OSErr ec;
  103.     
  104.     BlockMove (dataptr, &target, sizeof (target));
  105.     
  106.     if (target.location.locationKindSelector == ppcNoLocation) { /*local program*/
  107.         
  108.         ec = GetProcessSerialNumberFromPortName (&target.name, &psn);
  109.         
  110.         if (ec != noErr)
  111.             return (ec);
  112.         
  113.         info.processInfoLength = (long) sizeof (info);
  114.         
  115.         info.processName = nil;
  116.         
  117.         info.processAppSpec = nil;
  118.         
  119.         ec = GetProcessInformation (&psn, &info);
  120.         
  121.         if (ec != noErr)
  122.             return (ec);
  123.             
  124.         addressoftype = (Ptr) &info.processSignature;
  125.         }
  126.         
  127.     else { /*not a local program*/
  128.         
  129.         if (target.name.portKindSelector == ppcByCreatorAndType)
  130.             addressoftype = (Ptr) &target.name.u.port.creator;
  131.         else
  132.             addressoftype = ((Ptr) &target.name.u.portTypeStr) + 1; /*kloooge*/
  133.         }
  134.         
  135.     (*result).descriptorType = typeType;
  136.     
  137.     return (PtrToHand (addressoftype, &(*result).dataHandle, 4));
  138.     } /*CoerceTargetIDToType*/
  139.     
  140.     
  141. static pascal OSErr CoercePSNToType (DescType typecode, Ptr dataptr, Size datasize, DescType totype, long refcon, AEDesc *result) {
  142.     
  143.     ProcessInfoRec info;
  144.     OSErr ec;
  145.     
  146.     info.processInfoLength = (long) sizeof (info);
  147.     
  148.     info.processName = nil;
  149.     
  150.     info.processAppSpec = nil;
  151.     
  152.     ec = GetProcessInformation ((ProcessSerialNumber *) dataptr, &info);
  153.     
  154.     if (ec != noErr)
  155.         return (ec);
  156.         
  157.     (*result).descriptorType = typeType;
  158.     
  159.     return (PtrToHand (&info.processSignature, &(*result).dataHandle, 4));
  160.     } /*CoercePSNToType*/
  161.  
  162.  
  163. Boolean IACinit (void) {
  164.     
  165.     /*
  166.     returns true if the machine we're running on has Apple events, and if we are
  167.     able to install our coercion handlers. it may do more in future versions.
  168.     
  169.     call this routine before using any of the other iac.c routines. disable your
  170.     Apple event support if we return false.
  171.     
  172.     8/23/92 DW: only initialize once, no matter how many times we're called.
  173.     */
  174.     
  175.     static Boolean fl = false; 
  176.     
  177.     if (fl) 
  178.         return (true);
  179.         
  180.     fl = true;
  181.     
  182.     if (!IAChaveappleevents ())
  183.         return (false);
  184.         
  185.     if (!IACinstallcoercionhandler (typeProcessSerialNumber, typeType, (ProcPtr) &CoercePSNToType))
  186.         return (false);
  187.         
  188.     if (!IACinstallcoercionhandler (typeTargetID, typeType, (ProcPtr) &CoerceTargetIDToType))
  189.         return (false);
  190.         
  191.     IACglobals.idprocess = IACgetprocesscreator ();
  192.  
  193.     IACglobals.waitroutine = nil;
  194.     
  195.     IACglobals.nextparamoptional = false;
  196.         
  197.     return (true);
  198.     } /*IACinit*/
  199.     
  200.     
  201. Boolean IAChaveappleevents (void) {
  202.  
  203.     /*
  204.     return true if Apple Events are available.
  205.     */
  206.     
  207.     long gestaltAppleEventsPresent;
  208.     
  209.     if (Gestalt (gestaltAppleEventsAttr, &gestaltAppleEventsPresent) != noErr)
  210.         return (false);
  211.     
  212.     return (gestaltAppleEventsPresent != 0);
  213.     } /*IAChaveappleevents*/
  214.  
  215.  
  216.     
  217.     
  218.  
  219.